package filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 简单的过滤器
 *  post乱码过滤器
 */
public class ChaSetEndoFilter implements Filter {

    private String Encode=null;

    /**
     * 过滤器的初始化
     */
    @Override
    public void init(FilterConfig Config) throws ServletException {
        Encode=Config.getInitParameter("CODE");
        System.out.println("过滤器初始化"+Encode);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        response.setContentType("text/html;charset="+Encode);
        response.setCharacterEncoding(Encode);
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        System.out.println("过滤器的销毁");
    }
}
